package org.simple_blogging;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Extent;
import javax.jdo.Query;

public class BlogApp {

	private static BlogApp bAppInstance = new BlogApp();
	private PersistenceManager pm = PersistenceManagerFac.getInstance().getPersistenceManager();
	
	private BlogApp()
	{
	}
	
	public static BlogApp getInstance()
	{
		return bAppInstance;
	}
	
	public List<BlogEntry> getAllBlogEntries()
	{
		List<BlogEntry> retVal;
		
		Query query = pm.newQuery(BlogEntry.class);
	    query.setOrdering("dateSaved desc");

	    try {
	    	List<BlogEntry> result = (List<BlogEntry>) query.execute();
			retVal = result;
	    } finally {
	        query.closeAll();
	    }
		
		return retVal;
	}
}
